package com.br.android.widingwheels.adapter;

import java.text.DecimalFormat;
import java.util.Currency;
import java.util.List;
import java.util.Locale;

import com.br.android.widingwheels.R;
import com.br.android.widingwheels.entidades.Gasto;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListaCategoriasAdapter extends BaseAdapter{

	private Context context;
	private List<Gasto> listCategorias;
	
	public ListaCategoriasAdapter(Context context, List<Gasto> list){
		this.context = context;
		this.listCategorias = list;
	}
	
	@Override
	public int getCount() {
		return listCategorias.size();
	}

	@Override
	public Object getItem(int position) {
		return listCategorias.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Gasto g = listCategorias.get(position);
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.layout_adapter_lista_categorias, null);
		
		TextView textCategoria = (TextView) view.findViewById(R.id.textViewListaCategoriaNomeCategoria);
		TextView textValor = (TextView) view.findViewById(R.id.textViewListaCategoriaValorCategoria);
		
		Currency currency = Currency.getInstance(Locale.getDefault());
		DecimalFormat format = new DecimalFormat(currency.getSymbol() + " ###,###,##0.00");
		
		textCategoria.setText(g.getCategoriaGasto());
		textValor.setText(format.format(g.getValorGasto()));
		
		return view;
	}

}
